home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / Misc / SubmenuDelay < prev   
Text File  |  1991-05-10  |  3KB  |  64 lines

  1. unit SubmenuDelay;
  2.  
  3. interface
  4.  
  5. {These routines are handy for slowing down submenus when they're _really_ wide (> half screen)}
  6. {You should call IncreaseSubmenuDelay just before a call to PopUpMenuSelect when you know that}
  7. {the submenus may be wider than half of the screen width, and RestoreSubmenuDelay right after}
  8. {returning from PopUpMenuSelect.}
  9. {}
  10. {The submenu delay is how long an item must be selected before its submenu pops up. When a submenu}
  11. {is wider than half of the screen width, the menu manager has no choice but to pop it up right under the}
  12. {pointer. With the default delay (8 ticks), it's tough to get out of the submenu and down to the next item}
  13. {in the main menu. IncreaseSubmenuDelay records the original submenu delay and stretches this time out}
  14. {to 20 ticks (see newDelay). RestoreSubmenuDelay puts the delay back to its original setting.}
  15.  
  16.     procedure IncreaseSubmenuDelay;
  17.     procedure RestoreSubmenuDelay;
  18.  
  19. implementation
  20.  
  21.     var
  22.         savedMenuDelay: SignedByte;
  23.  
  24.     const
  25.         MBSaveLoc = $B5C;    {global at this address contains a handle to some menu info}
  26.         mbMenuDelay = $E;    {this offset in the handle holds the byte that controls the submenu delay}
  27.         newDelay = 20;
  28.  
  29. {    Pay attention now, I'm only going to tell you this once:}
  30. {}
  31. {    1)    MBSaveLoc is declared in the Private.a file which came with MPW. (I knew MPW was good for something.)}
  32. {    2)    Handle(MBSaveLoc) says that we want to use the constant as a pointer to a pointer.}
  33. {    3)    Handle(MBSaveLoc)^ gets the pointer I just mentioned, but…}
  34. {    4)    …that pointer is actually a handle, so Handle(Handle(MBSaveLoc)^) set us up to…}
  35. {    5)    …dereference the handle using Handle(Handle(MBSaveLoc)^)^, which gives us a pointer to the data.}
  36. {    6)    Now, we add an offset to that pointer, using ORD(Handle(Handle(MBSaveLoc)^)^)+mbMenuDelay, and…}
  37. {    7)    …coerce it to a byte pointer using Ptr(ORD(Handle(Handle(MBSaveLoc)^)^)+mbMenuDelay), which we save…}
  38. {    8)    …in the delayPtr variable so we can use delayPtr^ to reference the one byte we really want.}
  39. {}
  40. {    Any questions?}
  41. {}
  42. {    Oh, yeah, one more thing: Since MBSaveLoc is declared in Private.a, we're not supposed to know about}
  43. {    it, much less use it! If the submenus start behaving funny after some future rev of Apple's System SW,}
  44. {    I'd look here first for the cause of the problem…}
  45.     procedure IncreaseSubmenuDelay;
  46.         var
  47.             delayPtr: Ptr;
  48.     begin
  49.         delayPtr := Ptr(ORD(Handle(Handle(MBSaveLoc)^)^) + mbMenuDelay);
  50.         savedMenuDelay := delayPtr^;
  51.         if savedMenuDelay < newDelay then
  52.             delayPtr^ := newDelay;
  53.     end;
  54.  
  55. {Sorry, but I'm not going to explain all this again!}
  56.     procedure RestoreSubmenuDelay;
  57.         var
  58.             delayPtr: Ptr;
  59.     begin
  60.         delayPtr := Ptr(ORD(Handle(Handle(MBSaveLoc)^)^) + mbMenuDelay);
  61.         delayPtr^ := savedMenuDelay;
  62.     end;
  63.  
  64. end.